<script setup>
const props = defineProps({
  modelValue: { type: Object, default: () => ({}) },
  rootForm: { type: Object, default: () => ({}) },
  options: { type: Object, default: () => ({}) },
  disabled: Boolean
})

const emit = defineEmits(['update:modelValue'])

// 表单处理
const formRef = ref()
const form = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emit('update:modelValue', val)
  }
})
const validate = async () => {
  return new Promise(resolve => {
    formRef?.value.validate((valid, fields) => {
      resolve({ model: 'prove', name: '资质证明', success: valid, message: fields })
    })
  })
}

const accountType = computed(() => {
  const { collect } = props.rootForm.finance
  return { 1: !!collect.find(d => d.account_type === 1), 2: !!collect.find(d => d.account_type === 2) }
})

const clearValidate = () => {
  formRef?.value?.clearValidate()
}
const resetFields = () => {
  formRef?.value?.resetFields()
}
defineExpose({ validate, clearValidate, resetFields, formRef })
</script>

<template>
  <el-form ref="formRef" :model="form" label-position="top" :disabled="disabled">
    <div class="v-title mb-3">附件信息</div>
    <el-form-item label="" prop="business_license" :rules="[{ required: true, message: '营业执照不能为空', trigger: 'change' }]">
      <VUpload v-model="form.business_license" title="营业执照" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" required>
        三证合一证件不需上传开票资料和组织机构代码证，格式为jpg/jpeg/png/pdf，不超过5MB
      </VUpload>
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="tax_mark" :rules="[{ required: accountType[1], message: '开票资料不能为空', trigger: 'change' }]">
      <VUpload v-model="form.tax_mark" title="开票资料" multiple :required="accountType[1]" :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="organization_code" :rules="[{ required: accountType[1], message: '一般纳税人认定通知书不能为空', trigger: 'change' }]">
      <VUpload v-model="form.organization_code" title="一般纳税人认定通知书" multiple :required="accountType[1]" :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="collect_confirm" :rules="[{ required: accountType[2], message: '委托收款书不能为空', trigger: 'change' }]">
      <VUpload v-model="form.collect_confirm" title="委托收款书" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" :required="accountType[2]" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="id_copy">
      <VUpload v-model="form.id_copy" title="身份证复印件" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="bank_permit">
      <VUpload v-model="form.bank_permit" title="开户许可证" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="cooperate_protocol">
      <VUpload v-model="form.cooperate_protocol" title="收款证明图片附件" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="bank_copy">
      <VUpload v-model="form.bank_copy" title="银行卡复印件" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="check_report">
      <VUpload v-model="form.check_report" title="验厂报告" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
    <el-divider class="my-2" />
    <el-form-item label="" prop="other">
      <VUpload v-model="form.other" title="其他" multiple :types="['jpg', 'jpeg', 'png', 'pdf']" />
    </el-form-item>
  </el-form>
</template>
